const navigateTo = data =>{
  wx.navigateTo({
    url: data,
  })
}

const Back = number=>{
  wx.navigateBack({
    delta: number,
  })
}

const showTost = (test,icon)=>{
  wx.showToast({
    title: test,
    mask:true,
    icon: icon || 'none',
  })
}
const showModal =(text,state)=>{
  return new Promise((reslove,reject)=>{
    wx.showModal({
      title: '提示',
      content: text,
      showCancel:state?!state:true,
      success (res) {
        if (res.confirm) {
          reslove(true)
        } else{
          reslove(false)
        }
      }
    })
  })
}

const loading = text=>{
  wx.showLoading({
    title:text || '加载中',
    mask:true
  })
}

const hideL = ()=>{
  wx.hideLoading()
}

const showAction = (text,view,img)=>{
  return new Promise((reslove,reject)=>{
    wx.showActionSheet({
      itemList: [text,view,img],
      success (res) {
        if(res){
          reslove(res.tapIndex)
        }else{
          reject(res.errMsg)
        }
    }
  }) 
})
}

const switchT =()=>{
  wx.switchTab({
    url: '../user/user',
    success(res){
      wx.hideLoading()
    }
  })
}
module.exports = {
  navigateTo,
  showTost,
  showModal,
  loading,
  hideL,
  showAction,
  switchT
}